<div class="breadcrumbs breadcrumbs-fixed ace-save-state">
    <ul class="breadcrumb">
        <li>
            <i class="ace-icon fa fa-users home-icon"></i>
            <a href="#">种植管理</a>
        </li>
        <li class="active">平台收购果树订单列表</li>
    </ul>
</div>


<div class="page-content">
    <div class="row">
        <div class="col-xs-12">
            <h4 class="header smaller lighter blue">平台收购果树订单列表</h4>
            <div class="row">
                <div class="col-sm-3">
                </div>
                <div class="col-sm-9">
                    <form id="searchForm" class="form-inline text-right" role="search">
                        <select class="form-control input-sm" id="typeQuery" name="status">
                            <option value="">&nbsp;&nbsp;&nbsp;&nbsp;全部&nbsp;&nbsp;&nbsp;&nbsp;
                            </option>
                            <option value="1">&nbsp;&nbsp;&nbsp;&nbsp;待报价&nbsp;&nbsp;&nbsp;&nbsp;
                            </option>
                            <option value="2">&nbsp;&nbsp;&nbsp;&nbsp;已报价&nbsp;&nbsp;&nbsp;&nbsp;
                            </option>
                            <option value="3">&nbsp;&nbsp;&nbsp;&nbsp;已完成&nbsp;&nbsp;&nbsp;&nbsp;
                            </option>
                        </select>&nbsp;&nbsp;
                        <div class="input-group">
                            <input id="nameOrMobile" name="nameOrMobile" class="form-control input-sm" type="text"
                                   placeholder="用户名称/果树编号"/>
                            <span class="input-group-btn">
                                <button id="searchBtn" class="btn btn-xs btn-info" type="button">
                                    <i class="ace-icon fa fa-search"></i> 搜索
                                </button>
					        </span>
                        </div>
                    </form>
                </div>
            </div>
            <div class="space-6"></div>
            <div class="dataTables_wrapper form-inline no-footer">
                <table id="company-table" class="table table-striped table-bordered table-hover">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>用户昵称</th>
                        <th>果树编号</th>
                        <th>种植天数</th>
                        <th>申请时间</th>
                        <th>状态</th>
                        <th>价格</th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>

    <div id="manager-modal" class="bootbox modal fade in" tabindex="-1" role="dialog" aria-hidden="false">
        <div class="modal-dialog" style="width: 50%">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" data-dismiss="modal" class="bootbox-close-button close close-button">×
                    </button>
                    <h5 class="modal-title">近况编辑</h5>
                </div>
                <div class="modal-body">
                    <form id="manager-form" class="form-horizontal" role="form">
                        <div class="form-group">
                            <div class="col-sm-9">
                                <div class="clearfix">
                                    <input type="text" name="id" id="id" class="hidden">
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label no-padding-right" for="recyclePrice"> 收购报价：</label>
                            <div class="col-sm-9">
                                <div class="clearfix">
                                    <input type="text" name="recyclePrice" id="recyclePrice" class="col-xs-9"
                                           onkeyup="this.value=this.value.replace(/\D/g,'')"/>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" data-dismiss="modal" class="btn btn-sm btn-default close-button"><i
                            class="fa fa-undo"></i> 取消
                    </button>
                    <button id="save-manager-btn" type="button" class="btn btn-sm btn-primary"><i
                            class="fa fa-check"></i> 保存
                    </button>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        var company_table;
        var E = window.wangEditor;
        var editor = new E('#editor1');
        editor.customConfig.uploadImgServer = 'management/uploadArticleImg'; //上传路径
        editor.customConfig.uploadFileName = 'file'; //参数文件名
        editor.customConfig.uploadImgMaxSize = 2 * 1024 * 1024; //最大2M
        editor.customConfig.uploadImgMaxLength = 1; //每次上传一张
        editor.customConfig.menus = [
            'head',  // 标题
            'bold',  // 粗体
            'italic',  // 斜体
            'underline',  // 下划线
            'strikeThrough',  // 删除线
            'foreColor',  // 文字颜色
            'backColor',  // 背景颜色
            'link',  // 插入链接
            'list',  // 列表
            'justify',  // 对齐方式
            'quote',  // 引用
            'image',  // 插入图片
            'table',  // 表格
            'undo',  // 撤销
            'redo'  // 重复
        ];
        editor.create();

        $(function () {
            company_table = $('#company-table').DataTable({
                language: {url: 'ace/json/dataTable_CN.json'},
                autoWidth: false,
                ordering: false,
                searching: false,
                serverSide: true,
                processing: true,
                deferRender: true,
                responsive: true,
                ajax: {
                    url: 'management/recycleTreeOrder'
                },
                columns: [
                    {
                        data: 'id',
                        defaultContent: ''
                    },
                    {
                        data: 'name',
                        defaultContent: ''
                    }, {
                        data: 'goodsId',
                        defaultContent: ''
                    }, {
                        data: 'days',
                        defaultContent: ''
                    }, {
                        data: 'createTime',
                        defaultContent: ''
                    }, {
                        data: function (row) {
                            if (row.status === 1) {
                                return ' 待报价'
                            }
                            if (row.status === 2) {
                                return ' 已报价'
                            }
                            if (row.status === 3) {
                                return ' 已完成'
                            }
                        }
                    },
                    {
                        data: function (row) {
                            if (row.status === 1) {
                                return '&nbsp;&nbsp;<a id="editArticle" href="javascript:;" data-row="' + row + '" class="btn btn-xs btn-primary"><i class="fa fa-pencil"></i> 报价</a>';
                            } else {
                                return row.recyclePrice;
                            }
                        }
                    }
                ]
            });

            $('#searchBtn').click(function () {
                var param = $("#searchForm").serialize();
                company_table.ajax.url("management/recycleTreeOrder?" + param).load();
            });

            $('#company-table').find('> thead > tr > th input[type=checkbox]').eq(0).on('click', function () {
                $('#company-table').find('tbody > tr').find('input:checkbox').prop("checked", this.checked);
            });

            //点击编辑按钮，填充数据
            $("#company-table tbody").on("click", "#editArticle", function () {
                var row = company_table.row($(this).parents("tr")).data();
                $('#id').val(row.id);
                $("#manager-modal").modal("show");
            });

            //模态框隐藏事件
            $("#manager-modal").on("hide.bs.modal", function () {
                $("#manager-form")[0].reset();
                $("#imageUrl").prop("value", "");
            });

            $("#save-manager-btn").on("click", function () {
                if ($('#manager-form').valid()) {
                    $.post('management/addTreePrice', $('#manager-form').serialize(), function () {
                        $("#manager-modal").modal("hide");
                        company_table.ajax.reload();
                    });
                }
            });
        });
    </script>
</div>